Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: use PHPUnit Polyfills #277

Merged
merged 4 commits into from
Jun 22, 2021
Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 22, 2021

Composer: require-dev the PHPUnit Polyfills

While generally speaking, the require-dev for PHPUnit should now be removed, I'm leaving it in place due to the PHPUnit >= 9.3.0 issue with PHP-Parser backfilling tokens.
If/when that issue is resolved in the future, the direct requirement for PHPUnit can be removed.

Tests: update the bootstrap file

... to always check that a composer install has been run and to load the PHPUnit Polyfill autoloader directly when running PHPUnit via a Phar file as the Polyfill library needs to be installed and its autoload file loaded for the tests to work correctly.

Tests: add abstract PolyfilledTestCase

This test case extends the UtilityMethodTestCase from which most test classes extend and makes both the PHPCSUtils native AssertAttributeSame polyfill, as well as all polyfills from the PHPUnit Polyfill library available.

For test classes which don't need the set up and tear down methods contained in the UtilityMethodTestCase and would therefore normally extend the PHPUnit native TestCase, the PHPUnit Polyfill Yoast\PHPUnitPolyfills\TestCases\XTestCase can be extended instead.
Alternatively, such a test class can just use any of the polyfill traits from the PHPUnit Polyfill library directly.

Test classes which don't need the polyfilled assertion/expectation methods, can - and should - still just extend the PHPUnit native TestCase or the PHPCSUtils UtilityMethodTestCase directly.

Note: The list of included polyfill traits should be reviewed after each new (major/minor) release of the PHPUnit Polyfill library.

Tests: remove PHPUnit cross-version work-arounds

... in favour of using the PHPUnit Polyfills.

While generally speaking, the `require-dev` for PHPUnit should now be removed, I'm leaving it in place due to the PHPUnit >= 9.3.0 issue with PHP-Parser backfilling tokens.
If/when that issue is resolved in the future, the direct requirement for PHPUnit can be removed.
... to always check that a `composer install` has been run and to load the PHPUnit Polyfill autoloader directly when running PHPUnit via a Phar file as the Polyfill library needs to be installed and its autoload file loaded for the tests to work correctly.
This test case extends the `UtilityMethodTestCase` from which most test classes extend and makes both the PHPCSUtils native `AssertAttributeSame` polyfill, as well as all polyfills from the PHPUnit Polyfill library available.

For test classes which don't need the set up and tear down methods contained in the `UtilityMethodTestCase` and would therefore normally extend the PHPUnit native `TestCase`, the PHPUnit Polyfill `Yoast\PHPUnitPolyfills\TestCases\XTestCase` can be extended instead.
Alternatively, such a test class can just `use` any of the polyfill traits from the PHPUnit Polyfill library directly.

Test classes which don't need the polyfilled assertion/expectation methods, can - and should - still just extend the PHPUnit native `TestCase` or the PHPCSUtils `UtilityMethodTestCase` directly.

Note: The list of included polyfill traits should be reviewed after each new (major/minor) release of the PHPUnit Polyfill library.
... in favour of using the PHPUnit Polyfills.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Jun 22, 2021
@jrfnl jrfnl merged commit 64da18c into develop Jun 22, 2021
@jrfnl jrfnl deleted the feature/implement-phpunit-polyfills branch June 22, 2021 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant